<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@  taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<html>
<script src="./static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="./static/jquery-easyui-1.3.3/js/fy-alert.js"></script>
<link rel="stylesheet" type="text/css" href="./static/css/fy-alert.css">

<head>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.min.js"></script>
    <title>用户登录</title>
    <style>

                #verify {
                    height: 34px;
                    vertical-align: top;
                    font-size: 16px;
                }

                #code_img {
                    width: 100px;
                    height: 40px;
                    cursor: pointer;
                    vertical-align: top;
                }

        .panel {
            width: 45%;
            height: 50%;
            position: absolute;
            top: 20%;
            left: 26%;
        }

        .text {
            height: 100%;
            width: 40%;

            position: relative;
            left: 8%;
            top: 28%;
        }

        .right {
            border-left: 1px grey solid;
            border-left-width: thin;
            height: 70%;
            width: 60%;
            position: absolute;
            left: 44%;
            top: 20%;
        }

        #cn {
            font-family: 幼圆;
            font-size: 65px;
            color: orange;
        }

        #en {
            font-family: "Century Gothic";
            font-size: 35px;
            color: grey;
        }

        .bord {
            margin-left: 40px;
            width: 400px;
            height: 65px;
            border-radius: 8px;
            border-style: groove;
            position: relative;
            top: 10px;
            padding-left: 5%;
            font-size: 15px;
        }
        .bord_vcode {
            margin-left: 40px;
            width: 200px;
            height: 65px;
            border-radius: 8px;
            border-style: groove;
            position: relative;
            top: 10px;
            padding-left: 5%;
            font-size: 15px;
        }

        #subbtn {
            position: relative;
            left: 10%;
            top: 50%;
            width: 200px;
            height: 50px;
            background: orange;
            border: 0;
            color: white;
            font-size: 17px;
            border-radius: 8px;
        }

        #subbtn:hover {
            background: darkorange;
        }

        a {
            position: relative;
            left: 40px;
            top: 22px;
            color: orange;
            text-decoration: none;
        }

        a:hover {
            color: skyblue;
            text-decoration: underline;
        }


    </style>
</head>
<body>
<div class="background">
    <div class="panel">
        <div class="text">
            <div id="cn">博客</div>
            <div id="en">Grand&nbsp;&nbsp;&nbsp;&nbsp;Cloud</div>
        </div>
        <div class="right">
          <span>
        <form action="${pageContext.request.contextPath}/loginServlet">

            <input type="hidden" name="way" value="login">
            <input type="text" id="useName" name="userName" placeholder="请输入用户名" id="bord" class="bord" required> <br><br>

            <input type="password" id="password" name="passWord" placeholder="请输入密码" class="bord" required><br><br>
                <input type="text"  id="verify" name="verify" placeholder="请输入验证码" class="bord_vcode" required>
                <canvas width="100" height="40" id="verifyCanvas"></canvas>
                <img id="code_img">
    <br><br>
            <a href="register.html" id="">现在注册</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="登录" id="subbtn">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a
                href="forget.jsp">忘记密码</a>

        </form>

<script>


    $(document).ready(function() {
        //验证用户名
        $("#useName").blur(function () {
            var username = $('#useName').val()
            check(username)
        });
        //验证密码
        $("#password").blur(function () {
            var password = $('#password').val().toUpperCase();
            if(password == null || password == ""){
                alert("密码不允许为空")
            }
            // if(){
            //
            // }
        });
        //验证验证码
        $("#verify").blur(function() {
            var newRand=rand.join('').toUpperCase();
            console.log(newRand);
            //下面就是判断是否== 的代码，无需解释
            var oValue = $('#verify').val().toUpperCase();
            console.log(oValue)
            if (oValue == 0) {
                aniExtend({
                    title:"提示",
                    content:"请输入"
                });
                // alert("验证码不允许为空");
            } else if (oValue != newRand) {
                oValue = ' ';
                // alert("验证码输入的不对");
                aniExtend({
                    title:"提示",
                    content:"验证码输入的不对"
                });
            }
        })
    })


    var nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
        'L', 'M', 'N', 'O', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
        'y', 'z'
    ];
    var colors = []
    var rand = new Array();
    drawCode();
    // 绘制验证码
    function drawCode() {
        var canvas = document.getElementById("verifyCanvas"); //获取HTML端画布
        var context = canvas.getContext("2d"); //获取画布2D上下文
        context.fillStyle = "cornflowerblue"; //画布填充色
        context.fillRect(0, 0, canvas.width, canvas.height);
        // 创建渐变
        var gradient = context.createLinearGradient(0, 0, canvas.width, 0);
        gradient.addColorStop("0", "magenta");
        gradient.addColorStop("0.5", "blue");
        gradient.addColorStop("1.0", "red");
        //清空画布
        context.fillStyle = gradient; //设置字体颜色
        context.font = "25px Arial"; //设置字体

        var x = new Array();
        var y = new Array();
        for (var i = 0; i < 4; i++) {
            rand[i] = nums[Math.floor(Math.random() * nums.length)]
            x[i] = i * 16 + 10;
            y[i] = Math.random() * 20 + 20;
            context.fillText(rand[i], x[i], y[i]);
        }
        // console.log(rand);
        //画3条随机线
        for (var i = 0; i < 3; i++) {
            drawline(canvas, context);
        }

        // 画30个随机点
        for (var i = 0; i < 30; i++) {
            drawDot(canvas, context);
        }
        convertCanvasToImage(canvas)


    }
    // 随机线
    function drawline(canvas, context) {
        context.moveTo(Math.floor(Math.random() * canvas.width), Math.floor(Math.random() * canvas.height)); //随机线的起点x坐标是画布x坐标0位置，y坐标是画布高度的随机数
        context.lineTo(Math.floor(Math.random() * canvas.width), Math.floor(Math.random() * canvas.height)); //随机线的终点x坐标是画布宽度，y坐标是画布高度的随机数
        context.lineWidth = 0.5; //随机线宽
        context.strokeStyle = 'rgba(50,50,50,0.3)'; //随机线描边属性
        context.stroke(); //描边，即起点描到终点
    }
    // 随机点(所谓画点其实就是画1px像素的线，方法不再赘述)
    function drawDot(canvas, context) {
        var px = Math.floor(Math.random() * canvas.width);
        var py = Math.floor(Math.random() * canvas.height);
        context.moveTo(px, py);
        context.lineTo(px + 1, py + 1);
        context.lineWidth = 0.2;
        context.stroke();

    }
    // 绘制图片
    function convertCanvasToImage(canvas) {
        document.getElementById("verifyCanvas").style.display = "none";
        var image = document.getElementById("code_img");
        image.src = canvas.toDataURL("image/png");
        return image;
    }

    // 点击图片刷新
    document.getElementById('code_img').onclick = function () {
        $('#verifyCanvas').remove();
        $('#verify').after('<canvas width="100" height="40" id="verifyCanvas"></canvas>')
        drawCode();
    }
    //自定义弹出层动画
    function aniExtend(a){
        fyAlert.alert({
            title   : a.title,
            aniExtend:'lightSpeedIn',
            content : a.content,
            btns    : {                  //按钮组
                '确定' : function(obj){
                    obj.destory();   //在页面上

                },
                '取消' : function(obj){
                    obj.destory(); //销毁

                }
            },
        })
    }
</script>
         </span>
        </div>

    </div>
</div>

</body>
</html>
